package Chapter03;
//用do-while和for计算1+1/2！。。。。前20项的和
public class Question3 {
    public static void main(String args[]) {
        double sum=0,a=1,i=1;
        do { sum=sum+a;
            i++;
            a=(1.0/i)*a;
        }
        while(i<=20);
        System.out.println("do-while="+sum);
        for(sum=0,i=1,a=1;i<=20;i++) {
            a=a*(1.0/i);
            sum=sum+a;
        }
        System.out.println("for="+sum);
    }
}
